class Test:
  def __str__(self):
    return str(self.__dict__)

  def __init__(self,current_price, profit_per_hop, direction, bond, fund, defence_hands_arr):
    # 品种自身属性
    self.current_price = current_price
    self.profit_per_hop = profit_per_hop
    # 个人持仓情况
    self.direction =direction 
    self.bond = bond
    self.fund = fund

    # 主观计划
    self.defence_hands_arr = defence_hands_arr

    # 计算属性
    self.hands = sum(self.defence_hands_arr)
    self.stages = len(self.defence_hands_arr)
    self.hands_spend = self.hands * self.bond
    self.losts_spend = self.fund - self.hands_spend

    self.inteval = None
    self.get_inteval()
    self.inteval_percent = self.inteval/self.current_price
    self.defence_prices_percent = self.inteval * self.stages/self.current_price

  def get_inteval(self):
    losts_spend = self.losts_spend/self.profit_per_hop

    # for inteval in range(int(self.current_price*0.04),int(self.current_price*0.10)):
    for inteval in range(1,100000):
      losts = 0
      for n in range(0, self.stages):
        losts +=self.defence_hands_arr[n] * inteval * n 

      if losts >= losts_spend:
        self.inteval = inteval
        break


豆油 = Test(7662, 10, 1, 10000, 100000, [1,1,2,3]) 
# 纯碱 = Test(7662, 10, 1, 10000, 100000, [1,1,2,3])


print(豆油)
